

<!DOCTYPE html>
<html class="writer-html5" lang="zh" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>信号 &mdash; Scrapy 2.3.0 文档</title>
  

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster.custom.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster.bundle.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-shadow.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-punk.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-noir.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-light.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-borderless.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/micromodal.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/sphinx_rtd_theme.css" type="text/css" />

  
  
  
  

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script src="../_static/js/hoverxref.js"></script>
        <script src="../_static/js/tooltipster.bundle.min.js"></script>
        <script src="../_static/js/micromodal.min.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="条目导出器" href="exporters.html" />
    <link rel="prev" title="核心API" href="api.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home" alt="Documentation Home"> Scrapy
          

          
          </a>

          
            
            
              <div class="version">
                2.3
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">第一步</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intro/overview.html">Scrapy一目了然</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/install.html">安装指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/tutorial.html">Scrapy 教程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/examples.html">实例</a></li>
</ul>
<p class="caption"><span class="caption-text">基本概念</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="commands.html">命令行工具</a></li>
<li class="toctree-l1"><a class="reference internal" href="spiders.html">蜘蛛</a></li>
<li class="toctree-l1"><a class="reference internal" href="selectors.html">选择器</a></li>
<li class="toctree-l1"><a class="reference internal" href="items.html">项目</a></li>
<li class="toctree-l1"><a class="reference internal" href="loaders.html">项目加载器</a></li>
<li class="toctree-l1"><a class="reference internal" href="shell.html">Scrapy shell</a></li>
<li class="toctree-l1"><a class="reference internal" href="item-pipeline.html">项目管道</a></li>
<li class="toctree-l1"><a class="reference internal" href="feed-exports.html">Feed 导出</a></li>
<li class="toctree-l1"><a class="reference internal" href="request-response.html">请求和响应</a></li>
<li class="toctree-l1"><a class="reference internal" href="link-extractors.html">链接提取器</a></li>
<li class="toctree-l1"><a class="reference internal" href="settings.html">设置</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">例外情况</a></li>
</ul>
<p class="caption"><span class="caption-text">内置服务</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="logging.html">登录</a></li>
<li class="toctree-l1"><a class="reference internal" href="stats.html">统计数据集合</a></li>
<li class="toctree-l1"><a class="reference internal" href="email.html">发送电子邮件</a></li>
<li class="toctree-l1"><a class="reference internal" href="telnetconsole.html">远程登录控制台</a></li>
<li class="toctree-l1"><a class="reference internal" href="webservice.html">Web服务</a></li>
</ul>
<p class="caption"><span class="caption-text">解决具体问题</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../faq.html">常见问题</a></li>
<li class="toctree-l1"><a class="reference internal" href="debug.html">调试spiders</a></li>
<li class="toctree-l1"><a class="reference internal" href="contracts.html">蜘蛛合约</a></li>
<li class="toctree-l1"><a class="reference internal" href="practices.html">常用做法</a></li>
<li class="toctree-l1"><a class="reference internal" href="broad-crawls.html">宽爬行</a></li>
<li class="toctree-l1"><a class="reference internal" href="developer-tools.html">使用浏览器的开发人员工具进行抓取</a></li>
<li class="toctree-l1"><a class="reference internal" href="dynamic-content.html">选择动态加载的内容</a></li>
<li class="toctree-l1"><a class="reference internal" href="leaks.html">调试内存泄漏</a></li>
<li class="toctree-l1"><a class="reference internal" href="media-pipeline.html">下载和处理文件和图像</a></li>
<li class="toctree-l1"><a class="reference internal" href="deploy.html">部署蜘蛛</a></li>
<li class="toctree-l1"><a class="reference internal" href="autothrottle.html">AutoThrottle 扩展</a></li>
<li class="toctree-l1"><a class="reference internal" href="benchmarking.html">标杆管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="jobs.html">作业：暂停和恢复爬行</a></li>
<li class="toctree-l1"><a class="reference internal" href="coroutines.html">协同程序</a></li>
<li class="toctree-l1"><a class="reference internal" href="asyncio.html">asyncio</a></li>
</ul>
<p class="caption"><span class="caption-text">扩展Scrapy</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="architecture.html">体系结构概述</a></li>
<li class="toctree-l1"><a class="reference internal" href="downloader-middleware.html">下载器中间件</a></li>
<li class="toctree-l1"><a class="reference internal" href="spider-middleware.html">蜘蛛中间件</a></li>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">扩展</a></li>
<li class="toctree-l1"><a class="reference internal" href="api.html">核心API</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">信号</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#deferred-signal-handlers">延迟信号处理程序</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-scrapy.signals">内置信号参考</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#engine-signals">发动机信号</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#engine-started">engine_started</a></li>
<li class="toctree-l4"><a class="reference internal" href="#engine-stopped">engine_stopped</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#item-signals">项目信号</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#item-scraped">item_scraped</a></li>
<li class="toctree-l4"><a class="reference internal" href="#item-dropped">item_dropped</a></li>
<li class="toctree-l4"><a class="reference internal" href="#item-error">item_error</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#spider-signals">蜘蛛信号</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#spider-closed">spider_closed</a></li>
<li class="toctree-l4"><a class="reference internal" href="#spider-opened">spider_opened</a></li>
<li class="toctree-l4"><a class="reference internal" href="#spider-idle">spider_idle</a></li>
<li class="toctree-l4"><a class="reference internal" href="#spider-error">spider_error</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#request-signals">请求信号</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#request-scheduled">request_scheduled</a></li>
<li class="toctree-l4"><a class="reference internal" href="#request-dropped">request_dropped</a></li>
<li class="toctree-l4"><a class="reference internal" href="#request-reached-downloader">request_reached_downloader</a></li>
<li class="toctree-l4"><a class="reference internal" href="#request-left-downloader">request_left_downloader</a></li>
<li class="toctree-l4"><a class="reference internal" href="#bytes-received">bytes_received</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#response-signals">响应信号</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#response-received">response_received</a></li>
<li class="toctree-l4"><a class="reference internal" href="#response-downloaded">response_downloaded</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="exporters.html">条目导出器</a></li>
</ul>
<p class="caption"><span class="caption-text">其余所有</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../news.html">发行说明</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributing.html">为 Scrapy 贡献</a></li>
<li class="toctree-l1"><a class="reference internal" href="../versioning.html">版本控制和API稳定性</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Scrapy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
        
      <li>信号</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="signals">
<span id="topics-signals"></span><h1>信号<a class="headerlink" href="#signals" title="永久链接至标题">¶</a></h1>
<p>Scrapy广泛使用信号来通知某些事件何时发生。你可以在你的垃圾项目中捕捉到这些信号（使用 <a class="reference internal" href="extensions.html#topics-extensions"><span class="std std-ref">extension</span></a> 例如）执行其他任务或扩展scrapy以添加框外未提供的功能。</p>
<p>即使信号提供了几个参数，捕获它们的处理程序也不需要接受所有参数——信号调度机制只传递处理程序接收的参数。</p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-1466963416408457"
     data-ad-slot="8850786025"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>您可以通过 <a class="reference internal" href="api.html#topics-api-signals"><span class="std std-ref">信号API</span></a> .</p>
<p>下面是一个简单的示例，演示如何捕捉信号并执行某些操作：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">scrapy</span> <span class="kn">import</span> <span class="n">signals</span>
<span class="kn">from</span> <span class="nn">scrapy</span> <span class="kn">import</span> <span class="n">Spider</span>


<span class="k">class</span> <span class="nc">DmozSpider</span><span class="p">(</span><span class="n">Spider</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;dmoz&quot;</span>
    <span class="n">allowed_domains</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;dmoz.org&quot;</span><span class="p">]</span>
    <span class="n">start_urls</span> <span class="o">=</span> <span class="p">[</span>
        <span class="s2">&quot;http://www.dmoz.org/Computers/Programming/Languages/Python/Books/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/&quot;</span><span class="p">,</span>
    <span class="p">]</span>


    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_crawler</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">crawler</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">spider</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">DmozSpider</span><span class="p">,</span> <span class="bp">cls</span><span class="p">)</span><span class="o">.</span><span class="n">from_crawler</span><span class="p">(</span><span class="n">crawler</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">crawler</span><span class="o">.</span><span class="n">signals</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">spider</span><span class="o">.</span><span class="n">spider_closed</span><span class="p">,</span> <span class="n">signal</span><span class="o">=</span><span class="n">signals</span><span class="o">.</span><span class="n">spider_closed</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">spider</span>


    <span class="k">def</span> <span class="nf">spider_closed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spider</span><span class="p">):</span>
        <span class="n">spider</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Spider closed: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">spider</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>


    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span>
        <span class="k">pass</span>
</pre></div>
</div>
<div class="section" id="deferred-signal-handlers">
<span id="signal-deferred"></span><h2>延迟信号处理程序<a class="headerlink" href="#deferred-signal-handlers" title="永久链接至标题">¶</a></h2>
<p>一些信号支持返回 <a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html" title="(在 Twisted v2.0)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Deferred</span></code></a> 对象，允许您运行不阻塞Scrapy的异步代码。如果信号处理程序返回 <a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html" title="(在 Twisted v2.0)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Deferred</span></code></a> ，小淘气等着呢 <a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html" title="(在 Twisted v2.0)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Deferred</span></code></a> 开火。</p>
<p>举个例子：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">SignalSpider</span><span class="p">(</span><span class="n">scrapy</span><span class="o">.</span><span class="n">Spider</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;signals&#39;</span>
    <span class="n">start_urls</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;http://quotes.toscrape.com/page/1/&#39;</span><span class="p">]</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_crawler</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">crawler</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">spider</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">SignalSpider</span><span class="p">,</span> <span class="bp">cls</span><span class="p">)</span><span class="o">.</span><span class="n">from_crawler</span><span class="p">(</span><span class="n">crawler</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">crawler</span><span class="o">.</span><span class="n">signals</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">spider</span><span class="o">.</span><span class="n">item_scraped</span><span class="p">,</span> <span class="n">signal</span><span class="o">=</span><span class="n">signals</span><span class="o">.</span><span class="n">item_scraped</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">spider</span>

    <span class="k">def</span> <span class="nf">item_scraped</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="c1"># Send the scraped item to the server</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">treq</span><span class="o">.</span><span class="n">post</span><span class="p">(</span>
            <span class="s1">&#39;http://example.com/post&#39;</span><span class="p">,</span>
            <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">item</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;ascii&#39;</span><span class="p">),</span>
            <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="sa">b</span><span class="s1">&#39;Content-Type&#39;</span><span class="p">:</span> <span class="p">[</span><span class="sa">b</span><span class="s1">&#39;application/json&#39;</span><span class="p">]}</span>
        <span class="p">)</span>

        <span class="c1"># The next item will be scraped only after</span>
        <span class="c1"># deferred (d) is fired</span>
        <span class="k">return</span> <span class="n">d</span>

    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">quote</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">css</span><span class="p">(</span><span class="s1">&#39;div.quote&#39;</span><span class="p">):</span>
            <span class="k">yield</span> <span class="p">{</span>
                <span class="s1">&#39;text&#39;</span><span class="p">:</span> <span class="n">quote</span><span class="o">.</span><span class="n">css</span><span class="p">(</span><span class="s1">&#39;span.text::text&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(),</span>
                <span class="s1">&#39;author&#39;</span><span class="p">:</span> <span class="n">quote</span><span class="o">.</span><span class="n">css</span><span class="p">(</span><span class="s1">&#39;small.author::text&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(),</span>
                <span class="s1">&#39;tags&#39;</span><span class="p">:</span> <span class="n">quote</span><span class="o">.</span><span class="n">css</span><span class="p">(</span><span class="s1">&#39;div.tags a.tag::text&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">getall</span><span class="p">(),</span>
            <span class="p">}</span>
</pre></div>
</div>
<p>见 <a class="reference internal" href="#topics-signals-ref"><span class="std std-ref">内置信号参考</span></a> 下面要知道哪些信号支持 <a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html" title="(在 Twisted v2.0)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Deferred</span></code></a> .</p>
</div>
<div class="section" id="module-scrapy.signals">
<span id="built-in-signals-reference"></span><span id="topics-signals-ref"></span><h2>内置信号参考<a class="headerlink" href="#module-scrapy.signals" title="永久链接至标题">¶</a></h2>
<p>这是一个零碎的内置信号列表及其含义。</p>
<div class="section" id="engine-signals">
<h3>发动机信号<a class="headerlink" href="#engine-signals" title="永久链接至标题">¶</a></h3>
<div class="section" id="engine-started">
<h4>engine_started<a class="headerlink" href="#engine-started" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-engine_started"><span id="std:signal-engine_started"></span></span><dl class="py function">
<dt id="scrapy.signals.engine_started">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">engine_started</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.engine_started" title="永久链接至目标">¶</a></dt>
<dd><p>当废引擎开始爬行时发送。</p>
<p>此信号支持从其处理程序返回延迟。</p>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">注解</p>
<p>此信号可能被触发 <em>之后</em> 这个 <a class="reference internal" href="#std-signal-spider_opened"><code class="xref std std-signal docutils literal notranslate"><span class="pre">spider_opened</span></code></a> 信号，取决于蜘蛛是如何启动的。所以 <strong>不要</strong> 依靠这个信号 <a class="reference internal" href="#std-signal-spider_opened"><code class="xref std std-signal docutils literal notranslate"><span class="pre">spider_opened</span></code></a> .</p>
</div>
</div>
<div class="section" id="engine-stopped">
<h4>engine_stopped<a class="headerlink" href="#engine-stopped" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-engine_stopped"><span id="std:signal-engine_stopped"></span></span><dl class="py function">
<dt id="scrapy.signals.engine_stopped">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">engine_stopped</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.engine_stopped" title="永久链接至目标">¶</a></dt>
<dd><p>在报废引擎停止时发送（例如，当爬行过程完成时）。</p>
<p>此信号支持从其处理程序返回延迟。</p>
</dd></dl>

</div>
</div>
<div class="section" id="item-signals">
<h3>项目信号<a class="headerlink" href="#item-signals" title="永久链接至标题">¶</a></h3>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>最大值时 <a class="reference internal" href="settings.html#std-setting-CONCURRENT_ITEMS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CONCURRENT_ITEMS</span></code></a> 项是并行处理的，许多延迟是使用 <a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.DeferredList.html" title="(在 Twisted v2.0)"><code class="xref py py-class docutils literal notranslate"><span class="pre">DeferredList</span></code></a> . 因此，下一批将等待 <a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.DeferredList.html" title="(在 Twisted v2.0)"><code class="xref py py-class docutils literal notranslate"><span class="pre">DeferredList</span></code></a> 激发，然后为下一批报废的项运行相应的项信号处理程序。</p>
</div>
<div class="section" id="item-scraped">
<h4>item_scraped<a class="headerlink" href="#item-scraped" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-item_scraped"><span id="std:signal-item_scraped"></span></span><dl class="py function">
<dt id="scrapy.signals.item_scraped">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">item_scraped</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">item</span></em>, <em class="sig-param"><span class="n">response</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.item_scraped" title="永久链接至目标">¶</a></dt>
<dd><p>当一个项目被爬取时发送，当它通过所有 <a class="reference internal" href="item-pipeline.html#topics-item-pipeline"><span class="std std-ref">项目管道</span></a> 阶段（不下降）。</p>
<p>此信号支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>item</strong> (<a class="reference internal" href="items.html#item-types"><span class="std std-ref">item object</span></a>) -- 刮掉的东西</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 爬取项目的蜘蛛</p></li>
<li><p><strong>response</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object) -- 从项目被爬取的地方得到的响应</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="item-dropped">
<h4>item_dropped<a class="headerlink" href="#item-dropped" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-item_dropped"><span id="std:signal-item_dropped"></span></span><dl class="py function">
<dt id="scrapy.signals.item_dropped">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">item_dropped</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">item</span></em>, <em class="sig-param"><span class="n">response</span></em>, <em class="sig-param"><span class="n">exception</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.item_dropped" title="永久链接至目标">¶</a></dt>
<dd><p>从中删除项目后发送 <a class="reference internal" href="item-pipeline.html#topics-item-pipeline"><span class="std std-ref">项目管道</span></a> 当某个阶段 <a class="reference internal" href="exceptions.html#scrapy.exceptions.DropItem" title="scrapy.exceptions.DropItem"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DropItem</span></code></a> 例外。</p>
<p>此信号支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>item</strong> (<a class="reference internal" href="items.html#item-types"><span class="std std-ref">item object</span></a>) -- 从中删除的项 <a class="reference internal" href="item-pipeline.html#topics-item-pipeline"><span class="std std-ref">项目管道</span></a></p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 爬取项目的蜘蛛</p></li>
<li><p><strong>response</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object) -- 从中删除项的响应</p></li>
<li><p><strong>exception</strong> (<a class="reference internal" href="exceptions.html#scrapy.exceptions.DropItem" title="scrapy.exceptions.DropItem"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DropItem</span></code></a> exception) -- 例外情况（必须是 <a class="reference internal" href="exceptions.html#scrapy.exceptions.DropItem" title="scrapy.exceptions.DropItem"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DropItem</span></code></a> 子类）导致该项被删除</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="item-error">
<h4>item_error<a class="headerlink" href="#item-error" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-item_error"><span id="std:signal-item_error"></span></span><dl class="py function">
<dt id="scrapy.signals.item_error">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">item_error</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">item</span></em>, <em class="sig-param"><span class="n">response</span></em>, <em class="sig-param"><span class="n">spider</span></em>, <em class="sig-param"><span class="n">failure</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.item_error" title="永久链接至目标">¶</a></dt>
<dd><p>发送时 <a class="reference internal" href="item-pipeline.html#topics-item-pipeline"><span class="std std-ref">项目管道</span></a> 生成错误（即引发异常），除非 <a class="reference internal" href="exceptions.html#scrapy.exceptions.DropItem" title="scrapy.exceptions.DropItem"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DropItem</span></code></a> 例外。</p>
<p>此信号支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>item</strong> (<a class="reference internal" href="items.html#item-types"><span class="std std-ref">item object</span></a>) -- 中导致错误的项 <a class="reference internal" href="item-pipeline.html#topics-item-pipeline"><span class="std std-ref">项目管道</span></a></p></li>
<li><p><strong>response</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object) -- 引发异常时正在处理的响应</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 引发异常的蜘蛛</p></li>
<li><p><strong>failure</strong> (<a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.python.failure.Failure.html" title="(在 Twisted v2.0)"><em>twisted.python.failure.Failure</em></a>) -- 引发的异常</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
</div>
<div class="section" id="spider-signals">
<h3>蜘蛛信号<a class="headerlink" href="#spider-signals" title="永久链接至标题">¶</a></h3>
<div class="section" id="spider-closed">
<h4>spider_closed<a class="headerlink" href="#spider-closed" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-spider_closed"><span id="std:signal-spider_closed"></span></span><dl class="py function">
<dt id="scrapy.signals.spider_closed">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">spider_closed</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">spider</span></em>, <em class="sig-param"><span class="n">reason</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.spider_closed" title="永久链接至目标">¶</a></dt>
<dd><p>在蜘蛛关闭后发送。这可用于释放在上保留的每个蜘蛛资源 <a class="reference internal" href="#std-signal-spider_opened"><code class="xref std std-signal docutils literal notranslate"><span class="pre">spider_opened</span></code></a> .</p>
<p>此信号支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 已关闭的蜘蛛</p></li>
<li><p><strong>reason</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a>) -- 描述蜘蛛关闭原因的字符串。如果它是因为蜘蛛完成了爬取而关闭的，原因是 <code class="docutils literal notranslate"><span class="pre">'finished'</span></code> . 否则，如果通过调用 <code class="docutils literal notranslate"><span class="pre">close_spider</span></code> 引擎方法，则原因是 <code class="docutils literal notranslate"><span class="pre">reason</span></code> 该方法的参数（默认为 <code class="docutils literal notranslate"><span class="pre">'cancelled'</span></code> ）如果发动机停机（例如，按ctrl-c停止发动机），原因将是 <code class="docutils literal notranslate"><span class="pre">'shutdown'</span></code> .</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="spider-opened">
<h4>spider_opened<a class="headerlink" href="#spider-opened" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-spider_opened"><span id="std:signal-spider_opened"></span></span><dl class="py function">
<dt id="scrapy.signals.spider_opened">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">spider_opened</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.spider_opened" title="永久链接至目标">¶</a></dt>
<dd><p>在蜘蛛被打开爬行后发送。这通常用于为每个蜘蛛保留资源，但可用于打开蜘蛛时需要执行的任何任务。</p>
<p>此信号支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 已经打开的蜘蛛</p>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="spider-idle">
<h4>spider_idle<a class="headerlink" href="#spider-idle" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-spider_idle"><span id="std:signal-spider_idle"></span></span><dl class="py function">
<dt id="scrapy.signals.spider_idle">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">spider_idle</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.spider_idle" title="永久链接至目标">¶</a></dt>
<dd><p>当蜘蛛空闲时发送，这意味着蜘蛛没有更多：</p>
<blockquote>
<div><ul class="simple">
<li><p>等待下载的请求</p></li>
<li><p>计划的请求</p></li>
<li><p>正在项管道中处理的项</p></li>
</ul>
</div></blockquote>
<p>如果此信号的所有处理程序完成后空闲状态仍然存在，则引擎将开始关闭蜘蛛。蜘蛛完成闭合后， <a class="reference internal" href="#std-signal-spider_closed"><code class="xref std std-signal docutils literal notranslate"><span class="pre">spider_closed</span></code></a> 发送信号。</p>
<p>你可以举起 <a class="reference internal" href="exceptions.html#scrapy.exceptions.DontCloseSpider" title="scrapy.exceptions.DontCloseSpider"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DontCloseSpider</span></code></a> 防止蜘蛛关闭的异常。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 空转的蜘蛛</p>
</dd>
</dl>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">注解</p>
<p>在您的 <a class="reference internal" href="#std-signal-spider_idle"><code class="xref std std-signal docutils literal notranslate"><span class="pre">spider_idle</span></code></a> 处理程序 <strong>not</strong> 确保它可以防止蜘蛛被关闭，尽管有时可以。这是因为如果计划程序拒绝了所有计划的请求（例如，由于重复而被筛选），那么spider可能仍然处于空闲状态。</p>
</div>
</div>
<div class="section" id="spider-error">
<h4>spider_error<a class="headerlink" href="#spider-error" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-spider_error"><span id="std:signal-spider_error"></span></span><dl class="py function">
<dt id="scrapy.signals.spider_error">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">spider_error</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">failure</span></em>, <em class="sig-param"><span class="n">response</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.spider_error" title="永久链接至目标">¶</a></dt>
<dd><p>当spider回调生成错误（即引发异常）时发送。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>failure</strong> (<a class="reference external" href="https://twistedmatrix.com/documents/current/api/twisted.python.failure.Failure.html" title="(在 Twisted v2.0)"><em>twisted.python.failure.Failure</em></a>) -- 引发的异常</p></li>
<li><p><strong>response</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object) -- 引发异常时正在处理的响应</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 引发异常的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
</div>
<div class="section" id="request-signals">
<h3>请求信号<a class="headerlink" href="#request-signals" title="永久链接至标题">¶</a></h3>
<div class="section" id="request-scheduled">
<h4>request_scheduled<a class="headerlink" href="#request-scheduled" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-request_scheduled"><span id="std:signal-request_scheduled"></span></span><dl class="py function">
<dt id="scrapy.signals.request_scheduled">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">request_scheduled</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">request</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.request_scheduled" title="永久链接至目标">¶</a></dt>
<dd><p>在发动机排程A时发送 <a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> ，稍后下载。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>request</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object) -- 到达调度程序的请求</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 发出请求的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="request-dropped">
<h4>request_dropped<a class="headerlink" href="#request-dropped" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-request_dropped"><span id="std:signal-request_dropped"></span></span><dl class="py function">
<dt id="scrapy.signals.request_dropped">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">request_dropped</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">request</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.request_dropped" title="永久链接至目标">¶</a></dt>
<dd><p>发送时 <a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> 由引擎计划稍后下载的，被调度程序拒绝。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>request</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object) -- 到达调度程序的请求</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 发出请求的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="request-reached-downloader">
<h4>request_reached_downloader<a class="headerlink" href="#request-reached-downloader" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-request_reached_downloader"><span id="std:signal-request_reached_downloader"></span></span><dl class="py function">
<dt id="scrapy.signals.request_reached_downloader">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">request_reached_downloader</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">request</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.request_reached_downloader" title="永久链接至目标">¶</a></dt>
<dd><p>发送时 <a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> 已到达下载程序。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>request</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object) -- 到达下载程序的请求</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 发出请求的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="request-left-downloader">
<h4>request_left_downloader<a class="headerlink" href="#request-left-downloader" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-request_left_downloader"><span id="std:signal-request_left_downloader"></span></span><dl class="py function">
<dt id="scrapy.signals.request_left_downloader">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">request_left_downloader</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">request</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.request_left_downloader" title="永久链接至目标">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">2.0 新版功能.</span></p>
</div>
<p>发送时 <a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> 离开下载程序，即使在失败的情况下。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>request</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object) -- 到达下载程序的请求</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 发出请求的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="bytes-received">
<h4>bytes_received<a class="headerlink" href="#bytes-received" title="永久链接至标题">¶</a></h4>
<div class="versionadded">
<p><span class="versionmodified added">2.2 新版功能.</span></p>
</div>
<span class="target" id="std-signal-bytes_received"><span id="std:signal-bytes_received"></span></span><dl class="py function">
<dt id="scrapy.signals.bytes_received">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">bytes_received</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">request</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.bytes_received" title="永久链接至目标">¶</a></dt>
<dd><p>当收到特定请求的一组字节时，由http1.1和S3下载处理程序发送。对于同一请求，此信号可能被多次触发，每次都有部分数据。例如，一个25kb响应的可能场景是两个信号用10kb的数据触发，最后一个信号用5kb的数据触发。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> object) -- 下载处理程序接收的数据</p></li>
<li><p><strong>request</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object) -- 生成下载的请求</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 与响应关联的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">注解</p>
<p>此信号的处理程序可以通过引发 <a class="reference internal" href="exceptions.html#scrapy.exceptions.StopDownload" title="scrapy.exceptions.StopDownload"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopDownload</span></code></a> 例外情况。请参考 <a class="reference internal" href="request-response.html#topics-stop-response-download"><span class="std std-ref">停止下载响应</span></a> 主题以获取更多信息和示例。</p>
</div>
</div>
</div>
<div class="section" id="response-signals">
<h3>响应信号<a class="headerlink" href="#response-signals" title="永久链接至标题">¶</a></h3>
<div class="section" id="response-received">
<h4>response_received<a class="headerlink" href="#response-received" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-response_received"><span id="std:signal-response_received"></span></span><dl class="py function">
<dt id="scrapy.signals.response_received">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">response_received</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">response</span></em>, <em class="sig-param"><span class="n">request</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.response_received" title="永久链接至目标">¶</a></dt>
<dd><p>当发动机接收到新的 <a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> 从下载程序。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>response</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object) -- 收到的响应</p></li>
<li><p><strong>request</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object) -- 生成响应的请求</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 响应所针对的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这个 <code class="docutils literal notranslate"><span class="pre">request</span></code> 参数可能不包含到达下载程序的原始请求，如果 <a class="reference internal" href="downloader-middleware.html#topics-downloader-middleware"><span class="std std-ref">下载器中间件</span></a> 修改 <a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> 对象并设置特定的 <code class="docutils literal notranslate"><span class="pre">request</span></code> 属性。</p>
</div>
</div>
<div class="section" id="response-downloaded">
<h4>response_downloaded<a class="headerlink" href="#response-downloaded" title="永久链接至标题">¶</a></h4>
<span class="target" id="std-signal-response_downloaded"><span id="std:signal-response_downloaded"></span></span><dl class="py function">
<dt id="scrapy.signals.response_downloaded">
<code class="sig-prename descclassname">scrapy.signals.</code><code class="sig-name descname">response_downloaded</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">response</span></em>, <em class="sig-param"><span class="n">request</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.signals.response_downloaded" title="永久链接至目标">¶</a></dt>
<dd><p>由下载者在 <code class="docutils literal notranslate"><span class="pre">HTTPResponse</span></code> 是下载的。</p>
<p>此信号不支持从其处理程序返回延迟。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>response</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object) -- 已下载响应</p></li>
<li><p><strong>request</strong> (<a class="reference internal" href="request-response.html#scrapy.http.Request" title="scrapy.http.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object) -- 生成响应的请求</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><code class="xref py py-class docutils literal notranslate"><span class="pre">Spider</span></code></a> object) -- 响应所针对的蜘蛛</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
</div>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="exporters.html" class="btn btn-neutral float-right" title="条目导出器" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="api.html" class="btn btn-neutral float-left" title="核心API" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        
        &copy; 版权所有 2008–2020, Scrapy developers
      <span class="lastupdated">
        最后更新于 10月 18, 2020.
      </span>

    </p>
  </div>
    
    
    
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
  
 
<script type="text/javascript">
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.1.0";
analytics.load("8UDQfnf3cyFSTsM4YANnW5sXmgZVILbA");
analytics.page();
}}();

analytics.ready(function () {
    ga('require', 'linker');
    ga('linker:autoLink', ['scrapinghub.com', 'crawlera.com']);
});
</script>


</body>
</html>